home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
Lazy.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
3KB
|
99 lines
" NAME Lazy
AUTHOR miw@cs.man.ac.uk
FUNCTION implements lazy evaluation
ST-VERSION 2.2
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1
DATE 22 Jan 1989
SUMMARY Lazy implements lazy objects (which are given a block to compute
their value, but only do so on demand) MIW.
"
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 25 February 1988 at 9:51:47 pm'!
Object subclass: #Lazy
instanceVariableNames: 'result done args '
classVariableNames: ''
poolDictionaries: ''
category: 'Kernel-Processes'!
Lazy comment:
'I represent an execution which may not be required. I will
not start execution until at least one message has been
received. The messages sent to me are delayed until execution
has completed.'!
!Lazy methodsFor: 'initializing'!
block: aBlock
done _ false.
result _ aBlock.
args _ #()!
block: aBlock value: value
done _ false.
result _ aBlock.
args _ Array with: value!
block: aBlock value: value1 value: value2
done _ false.
result _ aBlock.
args _ Array with: value1 with: value2!
block: aBlock value: value1 value: value2 value: value3
done _ false.
result _ aBlock.
args _ Array with: value1 with: value2 with: value3!
block: aBlock valueWithArguments: anArray
done _ false.
result _ aBlock.
args _ anArray! !
!Lazy methodsFor: 'evaluating'!
doesNotUnderstand: aMessage
done ifFalse: "this really should be a critical region"
[result _ result valueWithArguments: args. done _ true].
^result perform: aMessage selector withArguments: aMessage arguments! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
Lazy class
instanceVariableNames: ''!
!Lazy class methodsFor: 'class initialisation'!
initialize
superclass _ nil "must avoid the checks"
"Lazy initialize"! !
Lazy initialize!
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 25 February 1988 at 9:51:56 pm'!
!BlockContext methodsFor: 'lazy evaluation'!
lazyValue
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self!
lazyValue: value
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self value: value!
lazyValue: value1 value: value2
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self value: value1 value: value2!
lazyValue: value1 value: value2 value: value3
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self value: value1 value: value2 value: value3!
lazyValueWithArguments: anArray
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self valueWithArguments: anArray! !